CCOPT=-fpic -O2 -Wall
CCDEBUG=-g

CC=g++    -D__LINUX__ -D_REENTRANT $(CCDEBUG) 

INCPATH=-I ../include -I ./
LDPATH=-L./
AR=ar -r

EXTRALIBSLIB=
CCCMD=$(CC) $(EXTRAFLAGS)  $(CCOPT) $(CCDEBUG) $(INCPATH)


all:

VERSION=1.7
GENSOCKLIB=libComPP.a
GENSOCKSHAREDLIB=libComPP-$(VERSION).so
SYSPLUSPLUS=sysplusplus

GENSOCKOBJECTS=Comm.o Socket.o SocketTcp.o SocketUnix.o  File.o\
Daemon.o   Poll.o SocketUdp.o Thread.o Sem.o Mutex.o\
Process.o Clone.o Launch.o   \
ShMem.o DirEntry.o Directory.o AClnt.o SClnt.o SSrv.o ASrv.o \
SSrvContext.o Context.o ASrvContext.o 

EXAMPLES=ExampleClient ExampleServer ExampleReceiver ExampleSender\
	ExampleBroadcastSender ExampleUdpSrv ExampleMulticastSender SockTest\
	ExampleMulticastReader ExampleThread ExampleClone ExampleLaunch  \
	ExampleSem ExampleDirEnt ExampleDirectory ExampleSocketUnix\
	ExampleSSrv ExampleSClnt UDPReceiver UDPSender ExampleASrv ExampleAClnt \
	ExampleEncDec SockTest ExampleSocketUnix ExampleSocketUnixDgram ExampleSignalling \
	ExampleReceiver ExampleThread

LDPATH=-L./ -L../lib
AR=ar -r 

LIBS=-lpthread -lrt

LLIBS=-lComPP -lSysPP $(EXTRALIBSLIB)
ifeq (yesx,yesx)
LIBLIST=$(GENSOCKLIB) $(GENSOCKSHAREDLIB)
else
LIBLIST=$(GENSOCKLIB) 
endif

HEADERFILES= Comm.h Daemon.h Mutex.h Process.h Sem.h SocketTcp.h Thread.h \
Clone.h File.h Launch.h Poll.h Socket.h SocketUdp.h ComPP ShMem.h DirEntry.h Directory.h \
SClnt.h SSrv.h AClnt.h ASrv.h


ALLLIBS=$(LLIBS) $(LIBS) 


# Configuration Section End


ExampleSignalling: ExampleSignalling.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleSignalling ExampleSignalling.o ${LLIBS} ${LIBS}

ExampleEncDec: ExampleEncDec.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleEncDec ExampleEncDec.o ${LLIBS} ${LIBS}

ExampleASrv: ExampleASrv.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleASrv ExampleASrv.o ${LLIBS} ${LIBS}

ExampleSem: ExampleSem.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleSem ExampleSem.o ${LLIBS} ${LIBS}

ExampleDirEnt: ExampleDirEnt.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleDirEnt ExampleDirEnt.o ${LLIBS} ${LIBS}

ExampleDirectory: ExampleDirectory.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleDirectory ExampleDirectory.o ${LLIBS} ${LIBS}

ExampleLaunch: ExampleLaunch.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleLaunch ExampleLaunch.o ${LLIBS} ${LIBS}

ExampleSleep: ExampleSleep.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleSleep ExampleSleep.o ${LLIBS} ${LIBS}

ExampleClone: ExampleClone.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleClone ExampleClone.o ${LLIBS} ${LIBS}

ExampleThread: ExampleThread.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleThread ExampleThread.o ${LLIBS} ${LIBS}

ExampleMulticastSender: ExampleMulticastSender.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleMulticastSender ExampleMulticastSender.o ${LLIBS} ${LIBS}

ExampleMulticastReader: ExampleMulticastReader.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleMulticastReader ExampleMulticastReader.o ${LLIBS} ${LIBS}

ExampleBroadcastSender: ExampleBroadcastSender.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleBroadcastSender ExampleBroadcastSender.o ${LLIBS} ${LIBS}

ExampleSender: ExampleSender.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleSender ExampleSender.o ${LLIBS} ${LIBS}

ExampleReceiver: ExampleReceiver.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleReceiver ExampleReceiver.o ${LLIBS} ${LIBS}

ExampleServer: ExampleServer.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleServer ExampleServer.o ${LLIBS} ${LIBS}

ExampleClient: ExampleClient.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleClient ExampleClient.o ${LLIBS} ${LIBS}

UDPSender: UDPSender.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o UDPSender UDPSender.o ${LLIBS} ${LIBS}

UDPReceiver: UDPReceiver.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o UDPReceiver UDPReceiver.o ${LLIBS} ${LIBS}


ExampleUdpSrv: ExampleUdpSrv.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleUdpSrv ExampleUdpSrv.o ${LLIBS} ${LIBS}

ExampleSSrv: ExampleSSrv.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleSSrv ExampleSSrv.o ${LLIBS} ${LIBS}

ExampleSClnt: ExampleSClnt.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleSClnt ExampleSClnt.o ${LLIBS} ${LIBS}

ExampleAClnt: ExampleAClnt.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleAClnt ExampleAClnt.o ${LLIBS} ${LIBS}

ExampleSocketUnix: ExampleSocketUnix.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleSocketUnix ExampleSocketUnix.o ${LLIBS} ${LIBS}

ExampleSocketUnixDgram: ExampleSocketUnixDgram.o ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o ExampleSocketUnixDgram ExampleSocketUnixDgram.o ${LLIBS} ${LIBS}


SockTest: SockTest.cpp ${GENSOCKLIB}
	$(CC) ${INCPATH} ${LDPATH} -o SockTest SockTest.cpp ${LLIBS} ${LIBS}

sysplusplus:
	make -C ../SysPlusPlus all


$(GENSOCKLIB): $(GENSOCKOBJECTS) 
	$(AR) $(GENSOCKLIB) $(GENSOCKOBJECTS)
	$(CC)   -shared  -o $(GENSOCKSHAREDLIB) $(GENSOCKOBJECTS)
	ln -sf $(GENSOCKSHAREDLIB) libComPP.so

preinstall: 
	cp ${LIBLIST} ../lib
	( cd ../lib ; ln -sf $(GENSOCKSHAREDLIB) libComPP.so )


#################################################################
########## Generic part from here ###############################
#################################################################

%.o:%.cpp
	$(CCCMD) -c   $*.cpp

%.o:%.cc
	$(CCCMD) -c   $*.cc

rebuild: clean all

clean:
	rm -f *.o $(LIBLIST) $(EXAMPLES) libComPP.so

#################################################################
#################### FINITO #####################################
#################################################################

all: sysplusplus ${GENSOCKLIB} preinstall ${EXAMPLES}  
